package com.example.springboot.controller;


import com.example.springboot.entity.GoodsEntity;
import com.example.springboot.mapper.GoodsMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "商品管理接口")
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    private GoodsMapper goodsMapper;

    @ApiOperation(value = "获取商品列表", notes = "获取系统中的所有商品信息")
    @GetMapping("/list")
    public List<GoodsEntity> list() {
        return goodsMapper.selectAll();
    }

    @ApiOperation(value = "根据分类获取商品列表", notes = "例如筛选“手机”这个分类下的商品")
    @ApiImplicitParam(name = "category", value = "分类", required = true, dataType = "String", paramType = "path", example = "手机")
    @GetMapping("/category/{category}")
    public List<GoodsEntity> listByCategory(@PathVariable String category) {
        return goodsMapper.selectByCategory(category);
    }
}
